package com.franklin.ideaplugin.mybatisrunner.utils;

import com.intellij.psi.xml.XmlTag;

import java.util.Objects;

/**
 * @author Ye Junhui
 * @since 2024/3/4
 */
public class MybatisXmlUtils {

    /**
     * 解析sql id
     * @param sqlTag
     * @return
     */
    public static String resolveSqlId(XmlTag sqlTag){
        //id
        String id = XmlUtils.getAttributeValue(sqlTag, "id");
        //获取mapper
        XmlTag parentTag = sqlTag.getParentTag();
        if (Objects.isNull(parentTag)){
            return id;
        }
        String namespace = XmlUtils.getAttributeValue(parentTag, "namespace");
        return namespace + "#" + id;
    }
}
